<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <textarea name="" id="" cols="30" rows="10" :value='ipt' v-model='ipt'></textarea>
        <button @click='btn'>发表</button>
        <div >
            <p v-for='(item,idx) in contents'>
                {{item.content}}  {{item.date}} {{item.like}}
                <button @click='like(idx)'>点赞</button><button @click='top(idx)'>置顶</button><button @click='del(idx)'>删除</button>
            </p>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        let vm = new Vue({
            el:'#app',
            data:{
                i:0,
                ipt:'',
                contents:[]
            },
            methods: {
                btn(){
                    if(this.ipt =='') return
                    this.contents.push({content:this.ipt,date:'11月',like:0})
                    this.i++
                    this.ipt='' 
                },
                like(idx){
                    this.contents[idx].like++
                },
                del(idx){
                    this.contents.splice(idx,1)
                },
                top(idx){   
                    this.contents.unshift(this.contents[idx])
                    this.contents.splice(idx+1,1)
                }
            }
        })
    </script>
</body>
</html>